package flexo.gui;

import flexo.graphic.GraphicSystem;
import flexo.graphic.Material;
import flexo.graphic.entity.Quad;
import flexo.math.Coords;
import flexo.scene.Node;

public class Image extends Widget
{
	protected Quad quad;
	
	public Image(String name, Coords size, String imageFile)
	{
		super(name,size);
		GraphicSystem gs = (GraphicSystem)flexo.Kernel.getSystem(GraphicSystem.ID);
		quad = gs.addQuad(size.x, size.y);
		
		if (!gs.existsMaterial(imageFile))
		{
			Material quadMat = gs.addMaterial(imageFile);
			quadMat.getShaderParam("tex").setValue(imageFile);
			quadMat.setBlending(Material.Blending.TRANSPARENT_ALPHA);
		}
		quad.setMaterial(imageFile);
	}
	
	@Override
	public boolean attachTo(Node n)
	{
		boolean result = super.attachTo(n);
		if (result)
		{
			quad.attachTo(n);
		}
		return result;
	}
	
	@Override
	public void deattachFrom(Node n)
	{
		quad.deattachFrom(n);
		super.deattachFrom(n);		
	}
}
